package cn.silver.module.message.service.impl;


import cn.silver.framework.mybatis.service.impl.BaseServiceImpl;
import cn.silver.module.message.bean.MessageBean;
import cn.silver.module.message.domain.MsgMessageUser;
import cn.silver.module.message.mapper.MsgMessageUserMapper;
import cn.silver.module.message.param.MessageParam;
import cn.silver.module.message.service.IMsgMessageUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 消息接收人信息Service业务层处理
 *
 * @author Silver.Zhou
 */
@Service
@Slf4j
public class MsgMessageUserServiceImpl extends BaseServiceImpl<MsgMessageUserMapper, MsgMessageUser, MessageParam, MessageBean>
        implements IMsgMessageUserService {

//    @Resource
//    private RabbitTemplate template;
//
//    @Override
//    public List<MsgSendModel> selectModels(String msgId, String channel) {
//        List<SysMsgReceiver> receivers = this.baseMapper.selectList(new QueryWrapper<SysMsgReceiver>().eq("msg_id", msgId)
//                .eq("channel", channel).eq("status", MsgResult.NO_SEND.getCode()));
//        return CollectionUtils.isNotEmpty(receivers) ? receivers.stream().map(SysMsgReceiver::convertModel).collect(Collectors.toList()) : Collections.emptyList();
//    }
//
//    @Override
//    public void updateMsgResult(MsgResultModel msgResultModel) {
//
//    }
//
//    @Override
//    public void updateReceiverStatus(SysMsgReceiver receiver, String status) {
//        receiver.setSendTime(new Date());
//        if (receiver.getSendNum() == null) {
//            receiver.setSendNum(1);
//        } else {
//            receiver.setSendNum(receiver.getSendNum() + 1);
//        }
//        receiver.setStatus(status);
//        this.update(receiver);
//    }

//    @Override
//    public void reSend(String id) {
//		SysMsgReceiver sysMsgReceiver = this.getById(id);
//		if (Objects.isNull(sysMsgReceiver)){
//			log.error("id:{},对应消息不存在",id);
//			throw new RuntimeException("对应消息不存在");
//		}
//
//		if (!MsgResult.FAILD.getCode().equals(sysMsgReceiver.getStatus())){
//			// 消息处在非失败状态,无需重复推送
//			log.error("id:{},对应消息不存在",id);
//			throw new RuntimeException("消息正在推送中,请勿重复推送");
//		}
//		// 1.更新消息状态
//		sysMsgReceiver.setStatus(MsgResult.NO_SEND.getCode());
//		this.updateById(sysMsgReceiver);
//
//		// 2.MQ重新推送消息
//		String routing = MsgChannel.getRouting(sysMsgReceiver.getChannel());
//		if (StringUtils.isNotEmpty(routing)){
//			this.template.convertAndSend(MsgQueueContant.EXCHANGE_KEY, routing, sysMsgReceiver.getMsgId());
//		}
//	}
}
